Page({

  /**
   * 页面的初始数据
   */
  data: {
    gameClass:"clickGame",
    rankingClass:"btnRanking",
    gamePadding:"gamePadding",
    rankingPadding:"ranking;",
    userhead: '',
    openid: '',
    username: '',
    history:'',
    j: 1
  },

  // btn1: function(){
  //   this.setData({
  //     gameClass:"clickGame",
  //     rankingClass: "btnRanking",
  //     gamePadding: "gamePadding",
  //     rankingPadding: "ranking;"
  //   })
  //   console.log(this.data.history)
  // },
  // btn2: function () {
  //   this.setData({
  //     gameClass: "btnGame",
  //     rankingClass: "clickRanking",
  //     gamePadding:"game",
  //     rankingPadding:"rankingPadding"
  //   })
  // },
  btn: function (event) {
    var userName = this.data.username
    var openid = this.data.openid
    var id = event.currentTarget.id
    console.log(id)
    console.log(userName)
    console.log(openid)
    wx.navigateTo({
      url: '../wx/wx?username=' + userName + '&openid=' + openid + '&id=' +id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this
    this.setData({
      username: options.username,
      openid: options.openid,
      userhead: options.userHead
    })

    wx.request({
      url: "https://www.zijike.com/userScore",
      data: {
        username: this.data.username,
        openid: this.data.openid
      },
      header: {
        'content-type': 'application/json'
      },
      success: (res) => {
        console.log(res.data.scoreList)
        var history = res.data.scoreList
        console.log(history)
        self.setData({
          history: history
        })
      }
    })
    // wx.connectSocket({
    //   url: 'wss://192.168.2.29:8080',
    //   success:(res)=>{
    //     console.log("成功")
    //   }
      
    // })
    // wx.onSocketOpen(function(res){
    //   console.log("socket已连接")
    //   wx.sendSocketMessage({
    //     data: [
    //       "aaa"
    //     ],
    //   })
    // })
    // wx.onSocketMessage(function(res){
    //   console.log("222222222222222222222222")
    //   console.log("接收到的信息"+res.data)
    //   console.log("222222222222222222222222")
    //   if(res.data==1){
    //     wx.request({
    //       url: "http://192.168.2.29/userScore",
    //       data: {
    //         username: self.data.username,
    //         openid: self.data.openid
    //       },
    //       header: {
    //         'content-type': 'application/json'
    //       },
    //       success: (res) => {
    //         console.log(res.data.scoreList)
    //         var history = res.data.scoreList
    //         console.log(history)
    //         self.setData({
    //           history: history
    //         })
    //       }
    //     })
    //   }
    // })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.startPullDownRefresh()
    setTimeout(function () {
      // complete
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    }, 1500);
    wx.request({
      url: "https://www.zijike.com/userScore",
      data: {
        username: this.data.username,
        openid: this.data.openid
      },
      header: {
        'content-type': 'application/json'
      },
      success: (res) => {
        console.log(res.data)
      }
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 如果是button转发按钮的打印
      console.log(res.target)
    }
    return {
      title: '炮弹记录',
      path: 'pages/history/history',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
    wx.showShareMenu({
      withShareTicket: true
    })
  }
})